/**
 * Created by 小虎Oni on 2016/9/3.
 */
'use strict';
app.controller('CouponCtrl', function($scope,UserService,TokenService,$state) {
  $scope.couponData =[]
  $scope.couponOldData=[]
  $scope.couponCard=[]
  $scope.couponOldCard=[]
  getCoupon();
  function getCoupon(){
    TokenService.getLocalUserId().then(function (user_id) {
      TokenService.getLocalToken().then(function (token) {
      UserService.getCoupons(user_id,token).then(function (res) {
        classCoupon(res);
      })
      })
    })
  }
  function classCoupon(data){
    for(var key in data){
      if(data[key].type == 1){//优惠卡
        if(data[key].status ==0){
          $scope.couponCard.push(data[key])
        }else{
          $scope.couponOldCard.push(data[key])
        }
      }else{//优惠卷
        if(data[key].status ==0){
          $scope.couponData.push(data[key])
        }else{
          $scope.couponOldData.push(data[key])
        }
      }
    }
    console.log(data)
  }
  $scope.goAddCoupon =function(){
    $state.go('addCoupon')
  };
});
